package com.xiehospital.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.xiehospital.common.core.domain.entity.SysReserve;
import com.xiehospital.system.service.ISysBedService;
import io.swagger.annotations.Api;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.xiehospital.common.annotation.Log;
import com.xiehospital.common.core.controller.BaseController;
import com.xiehospital.common.core.domain.AjaxResult;
import com.xiehospital.common.enums.BusinessType;
import com.xiehospital.common.core.domain.entity.SysBed;
import com.xiehospital.common.utils.poi.ExcelUtil;
import com.xiehospital.common.core.page.TableDataInfo;

/**
 * 床位信息Controller
 *
 * @author xierujian
 * @date 2024-02-21
 */
@RestController
@Api("床位")
@RequestMapping("/system/bed")
public class SysBedController extends BaseController
{
    @Autowired
    private ISysBedService sysBedService;

    /**
     * 查询床位信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:bed:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysBed sysBed)
    {
        startPage();
        List<SysBed> list = sysBedService.selectSysBedList(sysBed);
        return getDataTable(list);
    }

    /**
     * 导出床位信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:bed:export')")
    @Log(title = "床位信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysBed sysBed)
    {
        List<SysBed> list = sysBedService.selectSysBedList(sysBed);
        ExcelUtil<SysBed> util = new ExcelUtil<SysBed>(SysBed.class);
        util.exportExcel(response, list, "床位信息数据");
    }

    /**
     * 获取床位信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:bed:query')")
    @GetMapping(value = "/{bedId}")
    public AjaxResult getInfo(@PathVariable("bedId") Long bedId)
    {
        return success(sysBedService.selectSysBedByBedId(bedId));
    }

    /**
     * 新增床位信息
     */
    @PreAuthorize("@ss.hasPermi('system:bed:add')")
    @Log(title = "床位信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysBed sysBed)
    {
        return toAjax(sysBedService.insertSysBed(sysBed));
    }

    /**
     * 修改床位信息
     */
    @PreAuthorize("@ss.hasPermi('system:bed:edit')")
    @Log(title = "床位信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysBed sysBed)
    {
        return toAjax(sysBedService.updateSysBed(sysBed));
    }

    /**
     * 出院
     */
    @PreAuthorize("@ss.hasPermi('system:bed:discharge')")
    @Log(title = "床位信息", businessType = BusinessType.UPDATE)
    @GetMapping("/discharge/{bedId}")
    public AjaxResult discharge(@PathVariable Long bedId)
    {
        return toAjax(sysBedService.dischargeSysBed(bedId));
    }


    /**
     * 删除床位信息
     */
    @PreAuthorize("@ss.hasPermi('system:bed:remove')")
    @Log(title = "床位信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{bedIds}")
    public AjaxResult remove(@PathVariable Long[] bedIds)
    {
        return toAjax(sysBedService.deleteSysBedByBedIds(bedIds));
    }
}
